﻿using System;
using System.Collections;


namespace Chess_Model
{

    public class King : Piece
    {
        /*
        static void Main()
        {
            King king = new King(new Position(3, 3), 1);
            Position[] positions = king.getNextLegalMoves();

            foreach(Position a in positions)
            {
                Console.WriteLine("X: " + a.x + " Y: " + a.y);
            }

        }*/
        public King(Position position, int play)
        {
            pos     = position;
            player  = play;
        }

        // Generates a list of new legal positions from the current position
        // regardless of the other pieces' positions
        public override ArrayList getNextLegalMoves()
        {
            ArrayList positions      = new ArrayList();

            Position currentPosition = this.getCurrentPosition();

            for (int i = -1; i < 2; i++)
            {
                for (int j = -1; j < 2; j++)
                {
                    Position newPosition = new Position(currentPosition.x + i, currentPosition.y + j);

                    if (ChessUtilities.isInRange(newPosition.x, newPosition.y) &&
                        !newPosition.Equals(currentPosition))
                    {
                        positions.Add(newPosition);
                    }
                }
            }
            positions.Remove(pos);
            return positions; 
        }

        public override String toString()
        {
            return String.Format("{0}{1}", "Z", player);
        }
    }

}
